﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DATA
{
   public  class SupportOnlineSkypeREP
    {
        MODELGENERALDataContext context = new MODELGENERALDataContext();
        public List<SupportOnlineSkypeDTO> GetAllSupportOnlineSkypes()
        {
            List<SupportOnlineSkypeDTO> acc = new List<SupportOnlineSkypeDTO>();

            var acounts = from a in context.SupportOnlineSkypes
                          select a;
            foreach (var account in acounts)
            {
                SupportOnlineSkypeDTO sosDTO = new SupportOnlineSkypeDTO();
                sosDTO.DefaultString = account.defaultString;
                sosDTO.Nickname = account.nickname;
                sosDTO.SoID = account.soID;
                acc.Add(sosDTO);
            }
            return acc;
        }

       public bool AddSupportOnlineSkype(SupportOnlineSkypeDTO newAccount)
        {
            SupportOnlineSkype acc = new SupportOnlineSkype();
            try
            {
                acc.nickname = newAccount.Nickname;
                acc.defaultString = newAccount.DefaultString;
                context.SupportOnlineSkypes.InsertOnSubmit(acc);
                context.SubmitChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public void DeleteSupportOnlineSkype(int AccountID)
        {
            try
            {
                var acc = context.SupportOnlineSkypes.Single(a => a.soID == AccountID);
                context.SupportOnlineSkypes.DeleteOnSubmit(acc);
                context.SubmitChanges();
            }
            catch (Exception)
            {
                return;
            }


        }

        public bool UpdateSupportOnlineSkype(SupportOnlineSkypeDTO accountup)
        {
            try
            {
                SupportOnlineSkype acc = context.SupportOnlineSkypes.Single( nv => nv.soID == accountup.SoID);
                acc.nickname = accountup.Nickname;
                acc.defaultString = accountup.DefaultString;
                context.SubmitChanges();
            }

            catch (System.Exception ex)
            {
                return false;
            }
            return true;
        }

    }
}
